<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="/WEB-INF/jsp/include/easyui.jsp" %>
<title>实体配置</title>
<script>
	$(function(){
		/*
		* 参数
		*/
		var p = {
			gridUrl : "/console/com.fs.base.pojo.Modle/list" ,
			initUrl: "/console/modle/init",
			gridToolbar : "#gridToolbar"
		};
		var func = {
			createGridPage:function(className){
				window.parent.consoleFn.addTab('Grid设计【' + className + '】' ,'menuId_0','/console/modle/'+className+'/design/?type=grid');
			}
		};
		/*
		* 表格数据
		*/
		p.dataGrid = $("#dataGrid").datagrid({
			fit: true,
			rownumbers: true,
			pagination: true,
			pageSize:50,
			url: p.gridUrl,
			singleSelect: true, 
			idField: "id",
			columns: [[
				{field:"ck",checkbox:true},
				{field:"className",title:"实体名称",width:250},
				{field:"modleName",title:"模块名称",width:120},
				{field:"createTime",title:"创建时间",width:220},
				{field:"opt",title:"操作",width:220,formatter:function(value,row,index){
					return '&nbsp;<a class="pageOpt" href="javascript:void(0);" className="'+ row.className +'" opt="grid">页面辅助生成</a>&nbsp;' ;
				}}
			]],
			onLoadSuccess:function(data){
				$(".pageOpt").on("click",function(){
					var $this = $(this);
					var opt = $this.attr("opt"),
						className = $this.attr("className");
					switch(opt){
						case 'grid': func.createGridPage(className);break;
						default: break;
					}
				});
			},
			toolbar: p.gridToolbar
		});
		/*
		* 事件
		*/
		$(".easyui-linkbutton").on("click",function(){
			var id = $(this).attr("id");
			switch(id){
				case 'b_1':
					$.messager.confirm('温馨提示', '确认进行初始化实体操作？', function(r){
						if(r){
							$.getJSON(p.initUrl,function(json){
								if(json.flag){
									$.messager.show({ title:'我的消息', msg: '初始化成功！',timeout:3000, showType:'slide' });
									p.dataGrid.datagrid("reload");
								}else{
									$.messager.alert("温馨提示",json.msg,"warning");
								}
							});
						}
					});
					break;
				case 'b_5':
					p.dataGrid.datagrid("reload");
					break;
				case 'b_2':
					var rows = p.dataGrid.datagrid('getSelections');
					var len = rows.length ;
					if(len==1){
						var url = "/console/com.fs.base.pojo.Modle/delete";
						$.messager.confirm('确认对话框', "您确认删除当前选中记录？", function(r){if (r){
							$.getJSON(url, rows[0], function(result){
								p.dataGrid.datagrid('clearSelections');
								if(result.flag){
									p.dataGrid.datagrid("reload");
								} 
							});
						}});
					}
					break;
				default:break;
			}
		});
	});
</script>
</head>
<body>
	<div class="easyui-layout" style="height: 100%;width: 100%;">
		<div id="gridToolbar">
			<div class="gridButtons" class="easyui-panel" style="padding: 1px;">
				<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" id="b_1">初始化</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-no" plain="true" id="b_2">删除</a>
        		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="b_5">查询</a>
			</div>
		</div>
		
		<div region="center" border="false">
			<table id="dataGrid"></table>
		</div>
	</div>	
</body>
</html>